let app = getApp();
var siteinfo = require('../../siteinfo.js');
Page({
  data: {
    radioItems: [{
      name: '微信支付',
      image: '../../image/icon64_appwx_logo.png',
      value: '2',
      checked: true
    }],
  },

  onLoad: function(options) {
    this.setData({
      id: options.id
    })
    this.getCourseDetails()
  },

  onShow: function() {

  },
  //获取详情数据
  getCourseDetails: function() {
    var _this = this
    app._get(siteinfo.selCourseDetails, {
      id: _this.data.id
    }, function(result) {
      _this.setData(result.data);
    })
  },
  //微信支付
  toPay: function() {
    var _this = this;
    app._post_form(siteinfo.selCourseOrder, {
      id: _this.data.id
    }, function(result1) {
      if (_this.data.specialPrice != 0) {
        wx.navigateTo({
          url: '/pages/studyWxPay/studyWxPay?orderId=' + result1.data.orderId + '&specialPrice=' + _this.data.specialPrice + '&id=' + _this.data.id,
        })
      } else {
        wx.redirectTo({
          url: '/pages/studyPaySuccess/studyPaySuccess?total_fee=' + _this.data.specialPrice + '&id=' + _this.data.id,
        })
      }

    })
  },
  radioChange: function(e) {
    var radioItems = this.data.radioItems;
    for (var i = 0, len = radioItems.length; i < len; ++i) {
      radioItems[i].checked = radioItems[i].value == e.detail.value;
    }
    this.setData({
      radioItems: radioItems,
      pay_model: e.detail.value
    });
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
})